<template>
	<view class="order">
		<view class="tabsBox">
			<view class="title">
				我的订单
			</view>
			<view class="tabs">
			<!-- 	<view class="tabsitem" @click="handleTabs(0)">
					<image v-if="currIndex == 0" class="" src="@/static/image/alled.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/all.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 0}">
						待支付
					</view>
				</view> -->
				<view class="tabsitem" @click="handleTabs(1)">
					<image v-if="currIndex == 1" class="" src="@/static/image/bdzed.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/bdz.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 1}">
						已支付
					</view>
				</view>
				<view class="tabsitem" @click="handleTabs(2)">
					<image v-if="currIndex == 2" class="" src="@/static/image/dsd.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/dsded.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 2}">
						待送单
					</view>
				</view>
				<view class="tabsitem" @click="handleTabs(3)">
					<image v-if="currIndex == 3" class="" src="@/static/image/ysded.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/ysd.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 3}">
						已送单
					</view>
				</view>

			</view>

		</view>



		<view class="dataList">
			<view v-if="dataList.length>0" class="">
				<view class="outbox" v-for="(item,index) in dataList">
					<view class="orderNumber">
						<view class="">
							手机号：
						</view>
						<view class="">
							{{item.mobile}}
						</view>
						<view v-if="currIndex == 3" class="status">
							<image class="" src="@/static/image/ysz.png" style="width: 45.55rpx;height: 48rpx;" />
							<view class="" style="margin-left: 10rpx;">
								运输中
							</view>
						</view>
						<view v-if="currIndex == 0" class="buy" @click="buyOrder(item)">
							支付订单
						</view>
						<!-- <view v-if="currIndex == 4" class="payment">
							<view class="">
								剩余7天
							</view>
						</view> -->
					</view>
					<view class="contentBox">
						<view class="innerBox">
							<view class="info">
								<view class="avatar">
									<image class="" src="@/static/image/lovespecialist.png"
										style="width: 45.55rpx;height: 45.55rpx;" />
								</view>
								<view class="nikename">
									{{item.name}}
								</view>
							</view>

							<view class="message">
								<view class="name">
									{{item.good.name}}
								</view>
								<!-- <view class="shuliang">
									{{subitem.good_info.capacity}}L
								</view> -->
							</view>
							<view class="sumandnum">
								<view class="sum">
									￥{{item.good.price}}
								</view>
								<view class="num" style="color: #A7A7A7;">
									x{{item.count}}
								</view>
							</view>
						</view>

						<view class="dfk">
							<view v-if="item.status == 0" class="status">
								订单状态：待支付
							</view>
							<view v-if="item.status == 1" class="status">
								订单状态：已支付
							</view>
							<view v-if="item.status == 2" class="status">
								订单状态：待送单
							</view>
							<view v-if="item.status == 3" class="status" style="color: red;">
								订单状态：已送单
							</view>
							<!-- {{item.status}} -->
						</view>
					</view>

					<view v-if="currIndex > 2" class="driver">
						<view class="">
							司机：
						</view>
						<view class="">
							{{item.driver.name}}—{{item.driver.account}}
						</view>
					</view>
				</view>
			</view>

			<view v-else class="">
				<u-empty text="暂无订单" icon="http://cdn.uviewui.com/uview/empty/order.png">
				</u-empty>
			</view>
		</view>

		<view class="" style="height: 100rpx;"></view>

	</view>
</template>

<script>
	import {
		orderList,
		payment
	} from "@/api/api.js"
	export default {
		data() {
			return {
				currIndex: 1,
				dataList: []
			}
		},
		onLoad() {
			this.handleGetorderList()
		},
		methods: {
			async handleGetorderList() {
				this.dataList = []
				let res = await orderList()
				console.log("33", res)
				res.data.data.forEach((item, index) => {
					if (this.currIndex == item.status) {
						this.dataList.push(item)
					}
				})

			},

			handleTabs(index) {
				this.currIndex = index
				this.handleGetorderList()
			},
			async buyOrder(item) {
				let subres = await payment({
					out_trade_no: item.out_trade_no
				})
				if (subres.code == 1000) {
					uni.requestPayment({
						provider: 'wxpay',
						appId: subres.data.result.appId,
						timeStamp: subres.data.result.timeStamp,
						nonceStr: subres.data.result.nonceStr,
						package: subres.data.result.package,
						signType: subres.data.result.signType,
						paySign: subres.data.result.paySign,
						success(res) {
							console.log("支付成功、、、、、、、、、、、、、、、、")
							uni.showToast({
								title: '支付成功！',
								icon: "none",
								duration: 1500
							});
							setTimeout(() => {
								this.handleGetorderList()
							}, 2000)

						},
						fail(e) {
							uni.showToast({
								title: '支付失败！',
								icon: "none",
								duration: 1500
							});
						}
					})
				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
				}
			},

		}
	}
</script>

<style scoped lang="scss">
	.buy {
		width: 150rpx;
		height: 50rpx;
		background-color: #FF4E4E;
		text-align: center;
		line-height: 50rpx;
		color: #ffffff;
		border-radius: 10rpx;
		margin-left: 200rpx;
	}

	.order {
		.tabsBox {
			width: 702rpx;
			height: 250rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 0 auto;
			margin-top: 16rpx;
			padding: 16rpx;
			box-sizing: border-box;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #000000;
				line-height: 50rpx;
			}

			.tabs {
				display: flex;
				width: 100%;
				padding: 30rpx;
				box-sizing: border-box;
				justify-content: space-between;
				font-size: 28rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #000000;
				line-height: 50rpx;

				.tabsitem {
					text-align: center;
				}
			}
		}

		.dataList {


			.outbox {
				width: 702rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin: 0 auto;
				padding: 16rpx 24rpx;
				box-sizing: border-box;
				margin-bottom: 24rpx;

				.orderNumber {
					font-size: 24rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #000000;
					line-height: 50rpx;
					display: flex;

					.status {
						display: flex;
						margin-left: 180rpx;
					}

					.payment {
						font-size: 24rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #FF4E4E;
						line-height: 50rpx;
						display: flex;
						margin-left: 230rpx;

						.paymentbtn {
							width: 120rpx;
							height: 50rpx;
							background: #FF4E4E;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
							font-size: 24rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
							font-weight: 600;
							color: #FFFFFF;
							line-height: 50rpx;
							text-align: center;
						}
					}

				}

				.driver {
					font-size: 24rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #000000;
					line-height: 50rpx;
					display: flex;
				}

				.contentBox {
					width: 666rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 0rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					padding: 18rpx 16rpx;
					box-sizing: border-box;
					margin-bottom: 16rpx;
					margin-top: 10rpx;

					.innerBox {
						display: flex;
						justify-content: space-between;

						.info {
							display: flex;
							font-size: 28rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
							font-weight: 600;
							color: #000000;
							line-height: 50rpx;
						}

						.message {
							.name {
								width: 320rpx;
								height: 50rpx;
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #000000;
								line-height: 50rpx;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}

							.shuliang {
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #A7A7A7;
								line-height: 50rpx;
							}

						}

						.sumandnum {
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #000000;
							line-height: 50rpx;
							text-align: right;
						}
					}

					.dfk {
						font-size: 28rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #000000;
						line-height: 50rpx;
						// text-align: right;
						display: flex;
						justify-content: space-between;

					}
				}
			}
		}

	}
</style>